let phoneReg = /^(13[0-9]|15[012356789]|166|17[3678]|18[0-9]|14[57])[0-9]{8}$/
export const validatePhone = (rules, value) => {
    if (value === '') return Promise.reject('手机号不能为空')
    if (!phoneReg.test(value)) return Promise.reject('请输入正确的手机号')
    return Promise.resolve()
}

export const validatePassword = (rules, value) => {
    let pwdReg = /^.*(?=.{8,16})(?=.*\d)(?=.*[A-Za-z]+).*$/
    if (value === '') return Promise.reject('密码不能为空')
    if (!pwdReg.test(value)) return Promise.reject('密码必须包含数字和字母且长度为8~16位')
    return Promise.resolve()
}

export const validateCode = (rules, value) => {
    document.querySelector('.code-input-box').style.setProperty('border-color', '#ff4d4f', 'important')
    if (value === '') return Promise.reject('验证码不能为空')
    document.querySelector('.code-input-box').style.borderColor = '#d9d9d9'
    return Promise.resolve()
}

export const disabledGetYzmBtn = mobile => {
    return !mobile || !phoneReg.test(mobile)
}

export const formFailed = data => {
    if (data.values.code === '' || !Number.isInteger(data.values.code)) {
        document.querySelector('.code-input-box') ? document.querySelector('.code-input-box').style.setProperty('border-color', '#ff4d4f', 'important') : ''
    }
}
